home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
borland
/
prbgi097.zip
/
C.ZIP
/
BGIDEMO.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-12-15
|
12KB
|
408 lines
/* This program is not mine.
It was included with Turbo/Borland C(++)
and I only modified it a little to demonstrate
features of my PRINTBGI library.
It is included here for demonstration only
and cannot be used for any other purposes. ( Could it? ).
Original Copyright notice follows.
*/
/*
GRAPHICS DEMO FOR TURBO C 2.0
Copyright (c) 1987,88,90 Borland International. All rights reserved.
From the command line, use:
tcc bgidemo graphics.lib
*/
#define CRTtextmode1 0 // set to 1 if you don't want to use InterBGI driver
#ifdef __TINY__
#error BGIDEMO will not run in the tiny model.
#endif
#include <dos.h>
#include <math.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <graphics.h>
#include "prtgraph.h"
#include "BGIDEMO.H"
int GraphDriver; /* The Graphics device driver */
int GraphMode; /* The Graphics mode value */
static unsigned picwidth=4000,picheight=3000;
static int leftmargin=0,topmargin=0,
PicRotate=0, PicInverse=1;
static int PRTno;
static int mode;
static char OutName[MAXPATH]="PRN";
struct palettetype palette; /* Used to read palette info */
int static printing=0,asking=0;
int PRT_drv;
int PCXmode=0;
int ScreenPreview=1;
#define ESC 0x1b /* Define the escape key */
#include <assert.h>
#include <alloc.h>
#include "userprtf.c"
#include "harderrh.c"
/*-------------------*/
void grErrorTest(void)
/*-------------------*/
{ int ErrorCode;
ErrorCode = graphresult(); /* Read result of initialization*/
if( ErrorCode == grOk ) return;
/* Error occurred */
#if CRTtextmode1
closegraph();
#else
BGI_closegraph();
#endif
printf(" Graphics System Error: %s\n", PRT_grapherrormsg( ErrorCode ) );
PRT_End();
exit( 16 );
}
#ifdef __cplusplus
#define min(x,y) ((x)<=(y)? (x):(y))
#endif
/* */
/* CHANGETEXTSTYLE: similar to settextstyle, but checks for */
/* errors that might occur whil loading the font file. */
/* */
void changetextstyle(int font, int direction, int charsize)
{
int m;
int x,y;
graphresult(); /* clear error code */
if ( printing && font == DEFAULT_FONT )
{
PRT_Resolution ( &x,&y );
m = min ( y+60/120, getmaxx()/600+1 );
if (m>1) charsize *=m;
}
settextstyle(font, direction, charsize);
grErrorTest();
}
int _scanf( const char * format, ... )
{ va_list ap;
int c,r;
c=getchar();
if ( c=='\n' ) return 0;
va_start(ap,format);
ungetc(c,stdin);
r = vscanf (format,ap); (void)getchar();
va_end(ap);
return r;
}
/*-----------------------*/
void AskOfParameters(void)
/*-----------------------*/
{ int c,MAXmode;
const char *modename;
char s[MAXPATH];
clrscr();
cprintf ( "\n\r Output device name [%s]", OutName );
gets ( s ); if (*s!=0) strcpy(OutName,s);
cputs("\r\n");
PRT_SetOutName ( OutName );
cputs ( "\r\n Choose printer mode operation\r\n" );
PRT_MaxMode ( PRTno, &MAXmode );
for ( mode=0; mode<=MAXmode; mode++ )
{
PRT_ModeName(PRTno,mode,&modename );
cprintf ( " %2d - %s\r\n", mode, modename );
}
mode=MAXmode+1;
do
{
c=getch();
if (c==0) getch();
else if ((unsigned)c-'0'<=(unsigned)MAXmode) mode=c-'0';
}
while ( mode>MAXmode);
cprintf ( "\n\r Picture width in 1/1000 inch [%d] ", picwidth );
_scanf ( "%d", &picwidth );
cprintf ( " Picture height in 1/1000 inch [%d] ", picheight );
_scanf ( "%d", &picheight );
cprintf ( " Top margin in 1/1000 inch [%d] ", topmargin );
_scanf ( "%d", &topmargin );
cprintf ( " Left margin in 1/1000 inch [%d] ", leftmargin );
_scanf ( "%d", &leftmargin );
cprintf ( " Rotate picture [%d] ", PicRotate );
_scanf ( "%d", &PicRotate );
cprintf ( " Inverse picture [%d] ", PicInverse );
_scanf ( "%d", &PicInverse );
cprintf ( " Screen Preview [%d] ", ScreenPreview );
_scanf ( "%d", &ScreenPreview );
cprintf ( " PCX mode [%d] ", PCXmode );
_scanf ( "%d", &PCXmode );
}
/*---------------------------------*/
void DrawAndPrint ( int far func(void far * UserPointer), void far* UserPointer )
/*---------------------------------*/
{ int rc;
int PRT_mode=0;
do
{
asking=0;
printing=0;
func(UserPointer);
if ( asking )
{ int mode;
mode = BGI_getgraphmode(Scrn_BGIgroup);
restorecrtmode();
AskOfParameters();
BGI_setgraphmode( mode );
}
if ( printing ) /* Have user pressed Ctrl-P ? */
{
PRT_SetUserBeforeBuildFunc( BuildingMsg );
// PRT_SetDriver ( PRTno, mode,picwidth,picheight,
// ( PicRotate ? PRT_ROTATE:0 ) | ( PicInverse ? PRT_INVERSE:0 ) );
PRT_SetPrinterDrv ( PRTno, mode );
PRT_SetPictureInch ( picwidth,picheight,
( PicRotate ? PRT_ROTATE:0 ) |
( PicInverse ? PRT_INVERSE:0 ) );
PRT_SetMargins ( leftmargin, topmargin );
PRT_HaltPrinting = 0; // reset break indicator
rc=PRT_PrintBGI ( &PRT_drv, &PRT_mode, getenv("BGIPATH"), func, UserPointer );
#if CRTtextmode1
BGI_setgraphmode(mode);
#endif
if ( rc )
{ int mode;
mode=BGI_getgraphmode(Scrn_BGIgroup);
restorecrtmode();
cprintf ("\r\n error code %d (%s) from PRT_PrintBGI \r\n", rc,
PRT_grapherrormsg(rc) );
getch();
BGI_setgraphmode(mode);
}
}
}
while ( asking || printing );
}
/*-----------------*/
void InitPBGI(void)
/*-----------------*/
{
const char *PRTname;
int MaxPrinterNo;
int rc;
rc=PRT_ReadDrivers(getenv("BGIPATH"),"Printers.Def");
// rc=PRT_LinkDrivers();
if ( rc!=0 )
{
cputs ("\r\nSorry - I can't find drivers defintion file\r\n" );
exit(8);
}
clrscr();
cputs ( "\r\n\n\n"
"\n\rThis is a sample program (developed from Borland's BGIDEMO.C)"
"\n\rdemonstrating some of the features of PrintBGI toolkit"
"\n\rHope you'll find it usefull (the whole package not this program,"
"\n\rof course).\n\r"
"\n\rSince this is only an example program for demonstrating purposes"
"\n\rit uses standard C scanf function to input data with all"
"\n\rconsequences of it." );
cputs ( "\r\n"
"\r\nPlease, let me know if this program does not work with your printer."
"\r\nTo contact me write to RESZTAK@PLUMCS11.bitnet " );
cputs ( "\n\r \n\r Press any key to continue");
if ( getch()==0 ) getch();
clrscr();
MaxPrinterNo = PRT_MaxDriver();
cputs ( "\r\n Choose printer type\r\n" );
for ( PRTno=1; PRTno<=MaxPrinterNo; PRTno++ )
{
PRT_DriverName(PRTno,&PRTname );
cprintf ( " %2d - %s \r\n", PRTno, PRTname );
}
do
{
scanf( "%d",&PRTno);
(void)getchar();
}
while ( PRTno>MaxPrinterNo || PRTno<=0 );
clrscr();
PRT_drv = DETECT; /* <-- needed if you don't want link BitImage BGI driver */
PRT_drv = PRT_installuserdriver ( "BitImage", NULL );
rc = PRT_registerfarbgidriver ( BitImage );
AskOfParameters();
cputs ( "\r\n\r\n You will be able to change above parameters by pressing Ctrl-C." );
cputs ( "\n\r \n\r Press any key to continue");
if ( getch()==0 ) getch();
PRT_SetUserPrintFunc(StdUserPrtFunc);
}
#ifdef __cplusplus
void interrupt (*old_0x1b)(...);
#else
void interrupt (*old_0x1b)(void);
#endif
void restore_0x1b(void)
{
setvect(0x1b,old_0x1b);
}
/* */
/* Begin main function */
/* */